package com.lagou.test;

import com.lagou.mapper.ArticleMapper;
import com.lagou.domain.Article;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class test {

    SqlSession sqlSession;

    @Before
    public void before() throws IOException {
        InputStream in = Resources.getResourceAsStream("sqlMapConfig.xml");

        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);

        sqlSession = factory.openSession();


    }

    @After
    public void after() {
        sqlSession.close();
    }

    @Test
    public void test1() throws IOException {
        before();

        ArticleMapper mapper = sqlSession.getMapper(ArticleMapper.class);

        List<Article> articles = mapper.findArticleWithComment();

        for (Article article : articles) {
            System.out.println(article);
            System.out.println(article.getCommentList());
        }

        after();
    }
}
